package com.myecl.poker.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.myecl.poker.communication.ClientConnector;
import com.myecl.poker.state.Round;



public class InterfaceElements {
	
	public static JButton getFoldButton(final ClientConnector connector) {
		JButton button = new JButton("Fold");
		button.addActionListener(new ActionListener() {  
	        public void actionPerformed(ActionEvent e) {
	        	Thread queryThread = new Thread() {
	        		public void run() {
	        				connector.fold();    	 
	        		}
	        	};
	        	queryThread.start();
	        }
		});
		return button;
	}
	
	public static JButton getCheckButton(final ClientConnector connector) {
		JButton button = new JButton("Check");
		button.addActionListener(new ActionListener() {  
	        public void actionPerformed(ActionEvent e) {
	        	Thread queryThread = new Thread() {
	        		public void run() {
	        				connector.check();    	 
	        		}
	        	};
	        	queryThread.start();
	        }
		});
		return button;
	}
	
	public static JButton getCallButton(final ClientConnector connector) {
		JButton button = new JButton("Call");
		button.addActionListener(new ActionListener() {  
	        public void actionPerformed(ActionEvent e) {
	        	Thread queryThread = new Thread() {
	        		public void run() {
	        				connector.call(500.00);    	 
	        		}
	        	};
	        	queryThread.start();
	        }
		});
		return button;
	}
	
	

	
	
	public static JFormattedTextField getInputField() {
		final JFormattedTextField inputField = new JFormattedTextField(new DecimalFormat());
		inputField.setColumns(5);
		inputField.setMaximumSize(inputField.getPreferredSize());
		inputField.setInputVerifier(new BidVerifier());
		return inputField;
	}
	
	
	
	
	public static JButton getRaiseButton(final ClientConnector connector, final JTextField raiseField) {
		JButton button = new JButton("Raise");
		button.addActionListener(new ActionListener() {  
	        public void actionPerformed(ActionEvent e) {
	        	Thread queryThread = new Thread() {
	        		public void run() {
	        			if(raiseField.getInputVerifier().verify(raiseField)) {
	        				connector.raise(Double.valueOf(raiseField.getText()));
	        			}     	 
	        		}
	        	};
	        	queryThread.start();
	        }
		});
		return button;
	}
	
	public static JButton getFoldButton(Round round) {
		  JButton button = new JButton("Fold");
	      button.addActionListener(new ActionListener() {   
	        public void actionPerformed(ActionEvent e) {
	          Thread queryThread = new Thread() {
	            public void run() {           	 
	             }
	          };
	          queryThread.start();
	        }
	      });
	      return button;
		}
	
	
	public static JButton getStartButton(final View view) {
		  JButton button = new JButton("Start Round!");
	      button.addActionListener(new ActionListener() {   
	        public void actionPerformed(ActionEvent e) {
	          Thread queryThread = new Thread() {
	            public void run() {
	            	
	             }
	          };
	          queryThread.start();
	        }
	      });
	      return button;
		}
}
